home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 7.9 KB | 298 lines | [TEXT/MPS ] |
- /*
- File: HFSRecipient.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __HFSRECIPIENT__
- #include "HFSRecipient.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
- #ifndef __DEBUGGINGGEAR__
- #include "DebuggingGear.h"
- #endif
-
- /***********************************|****************************************/
-
- #pragma segment HFSRecipient
-
- /***********************************|****************************************/
-
- THFSRecipient::THFSRecipient(const RString& recipientName, Boolean responsible) :
- fResponsible (responsible),
- fRecipientType ('HFS '),
- fExtensionValue (nil) ,
- fStatus ( cUnknown )
- {
-
- fName = recipientName;
- fResponsible = responsible;
-
- // First, copy over the recipient name. The name is the part of the constructor
- // string which preceeds the '/', '-', or '|' in the address.
- for (unsigned short index = fName.dataLength-1; index > 0; --index)
- {
- if ((fName.body[index] == '/') || (fName.body[index] == '-') || (fName.body[index] == '|')) {
- fName.dataLength = index;
- }
- }
-
- fExtensionValue = nil;
- fPathNameElements = 0;
- for (index = 0; index < 8; ++index)
- fPathNameItems[index] = nil;
-
- fDirectoryName.dataLength = 0;
-
- // First, check whether this address is an extension-format, because it contains
- // a '/' character. If it is this format, then extract the part before the '/'
- // and put it into the extensionValue part of the address. Also put it in as
- // the recipientName. The address has no path or dNode information. Put the
- // four characters after the '/' into the address type field.
- for (index = 0; index < recipientName.dataLength; ++index) {
- if (recipientName.body[index] == '/') {
- // Sanity check that the type is == 4 characters
- if (recipientName.dataLength - index <= 4) {
- keith << "THFSRecipient: '/' address format should be data/TYPE, where TYPE=an OSType." << endl;
- }
- fRecipientType = * (OSType *) &recipientName.body[index+1];
-
- // Now copy the extension data into our fields.
- fExtensionValue = FAILNewPtrClear(index);
- for (short dataCopyIndex = 0; dataCopyIndex < index; ++dataCopyIndex) {
- fExtensionValue[dataCopyIndex] = recipientName.body[dataCopyIndex];
- }
- return;
- }
- }
-
- // Find a '-' in the name -- if it exists, then there is a path name, and so
- // we need to strip it out. We only look for path information if the address
- // is not an extension-type address.
- if ( fExtensionValue == nil )
- {
- for (index = 0; index < recipientName.dataLength; ++index) {
- if (recipientName.body[index] == '-') {
- RString temp;
-
- while ( ( index < recipientName.dataLength) &&
- (recipientName.body[index] != '|') )
- {
- temp.dataLength = 0;
- temp.charSet = smRoman;
- for (++index; ((index < recipientName.dataLength) &&
- (recipientName.body[index] != '-') &&
- (recipientName.body[index] != '|')); ++index) {
- temp.body[temp.dataLength++] = recipientName.body[index];
- }
-
- // Now make a copy of it.
- if ( temp.dataLength )
- {
- fPathNameItems[fPathNameElements] = (RStringPtr) FAILNewPtrClear( sizeof(ProtoRString) + temp.dataLength);
- fPathNameItems[fPathNameElements]->charSet = temp.charSet;
- fPathNameItems[fPathNameElements]->dataLength = temp.dataLength;
- BlockMove ( temp.body, & fPathNameItems[fPathNameElements]->body, temp.dataLength );
-
- ++fPathNameElements;
- }
- }
-
- // And, since there's a path name component, change the type of this
- // address to be the standard 20/20 recipient record type.
- fRecipientType = 'entn';
- }
- }
- }
-
- // If there is a '|' in the name, then the characters after that are the
- // directory name, so copy it over.
- for (index = 0; index < recipientName.dataLength; ++index) {
- if (recipientName.body[index] == '|') {
- fDirectoryName.dataLength = recipientName.dataLength - index - 1;
- fDirectoryName.charSet = smRoman;
- BlockMove (&recipientName.body[index+1], &fDirectoryName.body[0], fDirectoryName.dataLength);
- break;
- }
- }
- }
-
- /***********************************|****************************************/
-
- THFSRecipient::~THFSRecipient()
- {
- DisposeIfPtr(fExtensionValue);
-
- for (short index = 0; index < 8; ++index)
- DeallocatePtr ((Ptr) fPathNameItems[index]);
- }
-
- /***********************************|****************************************/
-
- Boolean THFSRecipient::GetResponsible() const
- {
- return fResponsible;
- }
-
- /***********************************|****************************************/
-
- Boolean THFSRecipient::GetRecipientName(TRString& name) const
- {
- name = fName;
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean THFSRecipient::GetRecipientType(TRString& type) const
- {
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean THFSRecipient::GetDirectoryName(DirectoryName& directoryName) const
- {
- if (fDirectoryName.dataLength > 0) {
- directoryName = fDirectoryName;
- return true;
- }
- return false;
- }
-
- /***********************************|****************************************/
-
- OSType THFSRecipient::GetAddressType() const
- {
- return fRecipientType;
- }
-
- /***********************************|****************************************/
-
- unsigned short THFSRecipient::GetPathNameCount () const
- {
- return fPathNameElements;
- }
-
- /***********************************|****************************************/
-
- void THFSRecipient::GetPathNameItem( unsigned short i, TRString &r ) const
- {
- r.SetLength ( 0 );
- r.SetScript ( smRoman );
-
- if ((i >= 0) && (i <= fPathNameElements))
- r = *(fPathNameItems[i-1]);
- }
-
- /***********************************|****************************************/
-
- Boolean THFSRecipient::GetCID(CreationID& cid) const
- {
- unused(cid);
- return false;
- }
-
- /***********************************|****************************************/
-
- unsigned long THFSRecipient::GetExtensionDataSize() const
- {
- return fName.dataLength;
- }
-
- /***********************************|****************************************/
-
- void THFSRecipient::GetExtensionData(unsigned long offset, void *buffer, unsigned long bufferSize) const
- {
- unsigned long dataToMoveSize = longmin(GetExtensionDataSize() - offset, bufferSize);
- BlockMove( (Ptr) (((char*) &fName.body)+offset), (Ptr) buffer, dataToMoveSize);
- }
-
- /***********************************|****************************************/
-
- Boolean
- THFSRecipient::SetStatus ( RecipientStatusSet status )
- {
- fStatus = status;
- return true;
- }
-
- /***********************************|****************************************/
-
- RecipientStatusSet
- THFSRecipient::GetStatus () const
- {
- return fStatus;
- }
-
- /***********************************|****************************************/
-
- ostream& THFSRecipient::DescribeSubclass( ostream& s ) const
- {
- s << "THFSRecipient:" << endl;
- return s;
- }
-
- /***********************************|****************************************/
-
- // This probably will never be called
- ostream& THFSRecipient::operator >> ( ostream& s ) const
- {
- TRString name;
-
- if (this == nil) {
- s << "THFSRecipient: nil" << flush;
- return s;
- }
-
- s << "THFSRecpt: '";
- if (GetRecipientName (name)) {
- s << name << " ";
- }
-
- s << "' status=" << GetStatus() << flush;
-
- return s;
- }
-
- /***********************************|****************************************/
-
- Boolean THFSRecipient::IsAddressTypePresent () const
- {
- return fRecipientType != 'entn';
- }
-
- /***********************************|****************************************/
-
- Boolean THFSRecipient::IsPathInfoPresent () const
- {
- return false;
- }
-
- /***********************************|****************************************/
-
- Boolean THFSRecipient::IsPathInfoOptional () const
- {
- return true;
- }
-
- /***********************************|****************************************/
-
- Boolean THFSRecipient::IsNameAndPathUnique ( ) const
- {
- return true;
- }
-
- /***********************************|****************************************/
-